package com.lkd.config;

import com.lkd.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author : Bing
 * @Date 2023/3/1 19:24
 */
@Slf4j
@Component
public class LoginConfig implements ApplicationContextAware {

    private Map<Integer,LoginService> loginServiceMap = new HashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        Map<String, LoginService> beansOfType =
                applicationContext.getBeansOfType(LoginService.class);

        beansOfType.values().forEach(each ->{
            loginServiceMap.put(each.getLoginType(),each);
        });

        log.info("LoginConfig");

    }

    public LoginService getLoginStrategyByLoginType(Integer loginType){
        return loginServiceMap.get(loginType);
    }
}
